www.gusucode.com > XerCMS 携云PHP企业建站程序 v2015PHP源码程序 > XerCMS 携云PHP企业建站程序 v2015/XerCMS_v20150724/XerCMS_v20150724/XerCMS/Library/XerCMS_error.php

    <?php
/**
 * @name     XERCMS
 * @author   Arno <XerCMS@163.com> [QQ:1328013]
 * @version  1.0.0
 * @link     http://www.XerCMS.com 
 */

!defined('XERCMS') && exit('Access Denied');

class error
{
     private static $errors;
	 
     static function show($title,$msg = '',$multi = false,$data = array()) {
		date_default_timezone_set('Asia/Hong_Kong');
	 	if(isset(X::$G['format']) && X::$G['format'] == 'json') {
		     $error = array('XerCMS'=>strtr((isset($data['str']) ? '('.$data['line'].')&nbsp;'.$data['str'] : $msg),array('"'=>'&#34;')));
			//if(!empty($data))
			     //$error['data'] = $data;
		     exit(json_encode($error));
		} else if ($multi == false) {
		     $html  = '<html><head><title>XERCMS Error!</title>';	
			$html .= '<style>*{font-size:12px;font-family:Microsoft Yahei,Arial;}body{padding:0px;margin:0px}a{text-decoration: none;color:red}
			.error{margin:30px auto 0px auto;border-radius:5px;width:80%;box-shadow:0px 0px 5px #666;opacity:0.9}
			.debug{display:table;width:100%;padding:0px;text-align:left} ul li{list-style:none;padding:5px 0px;line-height:14px;}ul li span{display:inline-block}
			ul li label{padding:0px 10px;width:30px;display:inline-block}ul li.url span,ul li.time span{width:50px}
			ul li span.index{width:50px;text-align:center;}ul li font.detail{background:#ddd;font-weight:800;padding:5px 0px;padding:5px 10px;}
			.head{font-size:18px;font-weight:800;background:#eee;border-top-left-radius:5px;border-top-right-radius:5px;padding:10px;border-bottom:1px solid #ddd}
			.foot{height:20px;line-height:20px;padding:5px 10px;background:#f3f3f3;border-top:1px solid #ddd}
			</style></head><body>';
		     $html .= '<div style="text-align:center"><div class="error"><div class="head">XERCMS '.(empty($title) ? 'Unknown' : $title).' Error!</div>';
		     //if(is_array($data))
			//{
			     $html .= '<ul class="debug">';
				$html .= '<li class="url"><label>URL</label>:&nbsp;&nbsp;'.$_SERVER['REQUEST_URI'].'</li>';
				$html .= '<li class="time"><label>Time</label>:&nbsp;&nbsp;'.date('Y-m-d H:i:s',X::$G['time']).'</li>';
	 	 	 	//foreach($data as $k=>$v) {
				     $html .= '<li><label>Detail</label>:&nbsp;&nbsp;<span>'.$data['file'].'&nbsp;&nbsp;('.$data['line'].')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font class="detail" style="color:#d51111">'.$data['str'].'</font></span></li>';
                    //}  
				$html .= '</ul>';
			//}     
		     $html .= '<div class="foot"><div style="float:left"><a href="http://www.xercms.com" target="_blank">Need Help?</a></div><div style="float:right">&copy; '.date('Y',X::$G['time']).' '.X::$G['sitename'].'</div></div></div></div></body></html>';			  
		     exit($html);
		} else if ($multi) {
		     $html  = '<html><head><title>XERCMS Error!</title>';	
			$html .= '<style>*{font-size:12px;font-family:Microsoft Yahei,Arial}body{padding:0px;margin:0px}
			a{text-decoration: none;color:red}
			html,body{height:100%;overflow:hidden;width:100%}
			.error{margin:50px auto 0px auto;border-radius:5px;overflow:hidden;width:80%;box-shadow:0px 0px 5px #666;opacity:0.9}
			.debug{display:table;width:100%;padding:0px;text-align:left} ul li{list-style:none;padding:5px 0px;line-height:14px;}ul li span{display:inline-block}
			ul li label{padding:0px 10px;width:30px;display:inline-block;}	
			ul li.msg span{display:inline-block;width:720px;vertical-align:top}
			ul li.line{background:#e8e8e8;margin:30px 10px;height:1px;padding:0px;}
			ul li.line font{position:relative;width:30px;border:1px solid #ddd;top:-5px;left:50%;margin-left:-15px;background:#fff;height:30px;padding:2px 10px;border-radius:5px;}
			ul li span.index{width:5%;text-align:center;}
			ul li span.file{width:25%;text-align:left;word-wrap:break-word}
			ul li span.line{width:5%;text-align:center;}
			ul li span.func{width:60%;text-align:left;}
			.head{font-size:18px;font-weight:800;background:#eee;border-top-left-radius:5px;border-top-right-radius:5px;padding:10px;border-bottom:1px solid #ddd}
			.foot{height:20px;line-height:20px;padding:5px 10px;background:#f3f3f3;border-top:1px solid #ddd}
			</style></head><body>';
		     $html .= '<div style="text-align:center"><div class="error"><div class="head">XERCMS '.(empty($title) ? 'Unknown' : $title).' Error!</div>';
		     //if(is_array($data)) {
			     $html .= '<ul class="debug">';
				$html .= '<li class="url"><label>URL</label>:&nbsp;&nbsp;'.$_SERVER['REQUEST_URI'].'</li>';
				$html .= '<li class="time"><label>Time</label>:&nbsp;&nbsp;'.date('Y-m-d H:i:s',X::$G['time']).'</li>';
				if(!empty($msg)) {
				     $html .= '<li class="msg"><label>Detail</label>:&nbsp;&nbsp;<span>'.$msg.'</span></li>';
				}
				$html .= '<li class="line"><font>DEBUG</font></li>';
	 	 	 	foreach($data as $k=>$v) {
				     $html .= '<li><span class="index">'.($k+1).'.</span><span class="file">'.$v['file'].'</span><span class="line">'.$v['line'].'</span><span class="func">'.$v['function'].'</span></li>';
                    }  
				$html .= '</ul>';
			//}     
		     $html .= '<div class="foot"><div style="float:left"><a href="http://www.xercms.com" target="_blank">Need Help?</a></div><div style="float:right">&copy; '.date('Y',X::$G['time']).' '.$G['sitename'].'</div></div></div></div></body></html>';			  
		     exit($html);
		}     		 
	}

     static function syserror($no,$msg,$file,$line) {
		  //$file = $file[1];
          if($no == E_NOTICE || $no == E_DEPRECATED) {
               return;
          }
		ob_clean();
		if(defined('XERCMS_DEBUG') && !XERCMS_DEBUG) {    
		     self::log($msg);exit('XERCMS Error!');
		}	  
		$trace = debug_backtrace();krsort($trace);
		$trace[] = array('file'=>$file, 'line'=>$line, 'function'=>'exit');
		$trace = self::trace($trace);	  
		self::show('System',self::checkpath($msg),true,$trace);
	}
	 
	static function log($str) {
	     file_put_contents(INC.'Logs/'.date('Ymd',X::$G['time']).'.log',$str."\r\n",FILE_APPEND);
	}
	 
	static function checkpath($file) {
	 	$file = strpos($file,'\\') ? strtr($file,array('\\'=>'/')) : $file;
          $replace[XERCMS] = '/';
          $replace[X::$CONFIG['tpldir']] = '......';
		$file = strpos($file,XERCMS) !== false ? strtr($file,$replace) : $file;
	 	return $file;		 
	}
	 
	static function trace($e) {
	     $ret = array();
		foreach($e as $k=>$err) {
		     $err['file'] = self::checkpath($err['file']);
               if(!empty($err['function'])) {
			     $err['function'] = (isset($err['class']) ? $err['class'] : '').(isset($err['type']) ? $err['type'] : '').$err['function'];
				$err['function'] .= '(';
			     if(isset($err['args'])) {	     
                         foreach($err['args'] as $i=>$v) {
						     /*
						     if(XERCMS_DEBUG)
							 {
							      if(is_array($v))
								  {
								       $err['args'][$i] = 'array';
								  } else if (is_object($v))
								  {
								       $err['args'][$i] = 'object';
								  } else 
								  {
								       $err['args'][$i] = htmlchars($v);
								  }
							 }
							 */
						$err['args'][$i] = gettype($v);//'$'.$i;
						 
					}
                         $err['function'] .= implode(',',$err['args']);	
                         						 
				}
				$err['function'] .= ')';
				$ret[] = $err;
			}		   
		}
		return $ret;
	}
	 
     static function exception($e) {
	     ob_clean();
		$trace = $e->getTrace();krsort($trace);
		$trace[] = array('file'=>$e->getFile(), 'line'=>$e->getLine(), 'function'=>'exit');
          $trace = self::trace($trace);
		if($e instanceof DbError) {
		     $title = 'Database';
		} else if ($e instanceof TpError) {
		     $title = 'Template';
		} else $title = 'System';
		self::show($title,self::checkpath($e->getMessage()),true,$trace);
	 }
	 
     static function shutdown() {
	     if(($e = error_get_last()) != NULL) {
		     if($e['type'] == E_NOTICE || $e['type'] == E_DEPRECATED || $e['type'] == E_WARNING) {
               	return;
              	}
		     $e['file'] = self::checkpath($e['file']);
		     $trace = array('file'=>$e['file'], 'line'=>$e['line'],'str'=>$e['message']);
		     self::show('Php','',false,$trace);
		}
	} 
}
?>